/**
 * Created by jerome.arnoult on 15/05/14.
 */

/**
 * Colors
 * - Structures :
 *      =Spawn:         #FFFFD4
 *      =Corridor:      #878787
 *      =Extractor:     #888AC2
 *      =Generator:     #E6C70A
 *      =Biodome:       #52C11E
 *      =Kitchen:       #ED5751
 *      =LifeRoom:      #DC4CD0
 *      =DefenceArea:   #5B97F9
 *      =Research:      #62FAFA
 *      =Infirmary:     #?????? // TODO : Choisir couleur pour infirmerie
 *      =DefenceAntiAir:#888DD4
 *      =Airport:       #F30707
 *      =Bunker:        #683200 // TODO : changer couleur pas assez visible
 *
 * - Entities (foncé, medium et clair) :
 *      =Thorium:   #5558A7, #7275C9, #888AC2
 *      =Energy:    #EEC922, #F4DD74
 *      =Harvest:   #7EA941, #9EC567
 *      =Food:      #EA1A1A, #F06262
 *
 * - Noids :
 *      =Supplier:  #FFF
 *      =Engineer:  #F1A829
 *      =Miner:     #F0F0F0
 *      =Harvester: #80D11D
 *      =Cooker:    #F8C1C0
 *      =defender:  #C9DDFD
 *      =researcher:#E2FEFE
 *
 * - Player :
 *      #1: #00EFFF
 *      #2: #FFF4B3
 *
 * - ERROR CONSTRUCT : #FF4949
 */



function gamerenderer(idCanvas, stage){
    this.stage = stage;
    this.intervalRender;//used only in horrible case of outdated browser
    this.stopRendering = true;
    this.optimizeRender(idCanvas, stage);
    this.toggleFPS = false;
    this.FPS;

    this.useTicker = true;

    //Graphics
    this.padding = 5;
}
//Perform optim
gamerenderer.prototype.optimizeRender = function(idCanvas, stage){
    var canvas = document.getElementById(idCanvas);
    canvas.width = (window.innerWidth) >>0;
    canvas.style.width = window.innerWidth + 'px';
    canvas.height = (window.innerHeight) >>0;
    canvas.style.height = window.innerHeight + 'px';
}
//Queueing frame
gamerenderer.prototype.queueNewFrame = function(){
    if (window.requestAnimationFrame)
        window.requestAnimationFrame(game.gameRenderer.renderingLoop);
    else if (window.msRequestAnimationFrame)
        window.msRequestAnimationFrame(game.gameRenderer.renderingLoop);
    else if (window.webkitRequestAnimationFrame)
        window.webkitRequestAnimationFrame(game.gameRenderer.renderingLoop);
    else if (window.mozRequestAnimationFrame)
        window.mozRequestAnimationFrame(game.gameRenderer.renderingLoop);
    else if (window.oRequestAnimationFrame)
        window.oRequestAnimationFrame(game.gameRenderer.renderingLoop);
    else {
        game.gameRenderer.queueNewFrame = function () {};
        intervalRender = window.setInterval(game.gameRenderer.renderingLoop, 16.7);
    }
}
//Render loop
gamerenderer.prototype.renderingLoop = function(){
    if(this.useTicker){
        createjs.Ticker.setFPS(60);
        createjs.Ticker.addEventListener("tick",function(e){
            if(!e.paused){
                //game.gameMap.update();
                game.stage.update();
                if(game.gameRenderer.toggleFPS === true)
                    game.gameRenderer.FPS = createjs.Ticker.getMeasuredFPS();
            }
        });
    }else{
        if(!game.gameRenderer.stopRendering){
            //game.gameMap.update();
            game.stage.update();
        }
        game.gameRenderer.queueNewFrame();
    }
}
//Ticker

//Resources
gamerenderer.prototype.createResourceCloud = function(x, y, size){
    var shape = new createjs.Shape();
    shape.regX = 0;
    shape.regY = 0;
    shape.x = x;
    shape.y = y;
    shape.zIndex = 100;
    switch(size){
        case "large":
            //5x5
            var gabarit = new createjs.Shape();
            gabarit.regX = 0;
            gabarit.regY = 0;
            gabarit.x = x;
            gabarit.y = y;
            gabarit.graphics
                .beginFill("#fff")
                .drawEllipse((game.gameMap.tileWidth/4)-(game.gameMap.tileWidth * 2)>>0, (game.gameMap.tileHeight/4)-(game.gameMap.tileHeight * 2)>>0, ((game.gameMap.tileWidth * 4)-(game.gameMap.tileWidth/4))>>0, ((game.gameMap.tileHeight*4)-(game.gameMap.tileHeight/4))>>0)
                .endFill();
            //game.mainContainer.addChild(gabarit);

            for(var i = 0; i<100; i++){
                var circleX = ((Math.random() - 0.5) * (game.gameMap.tileWidth*4))>>0;
                var circleY = ((Math.random() - 0.5) * (game.gameMap.tileHeight*4))>>0;
                if(gabarit.hitTest(circleX, circleY)){
                    shape.graphics
                        .beginFill("rgba(136,138,194,0.3)")
                        .drawCircle(circleX, circleY, (game.gameMap.tileHeight/4)>>0)
                        .endFill()
                        .beginFill("rgba(85,88,167,0.9)")
                        .rect(circleX-1, circleY-1, 2, 2)
                        .endFill();
                }else{
                    i--;
                }
            }
            break;

        default:
        case "medium":
            //3x3
            var gabarit = new createjs.Shape();
            gabarit.regX = 0;
            gabarit.regY = 0;
            gabarit.x = x;
            gabarit.y = y;
            gabarit.graphics
                .beginFill("#fff")
                .drawEllipse((game.gameMap.tileWidth/4)-game.gameMap.tileWidth, (game.gameMap.tileHeight/4)-game.gameMap.tileHeight, ((game.gameMap.tileWidth * 2)-(game.gameMap.tileWidth/4))>>0, ((game.gameMap.tileHeight*2)-(game.gameMap.tileHeight/4))>>0)
                .endFill();
            //game.mainContainer.addChild(gabarit);

            for(var i = 0; i<40; i++){
                var circleX = ((Math.random() - 0.5) * (game.gameMap.tileWidth*2))>>0;
                var circleY = ((Math.random() - 0.5) * (game.gameMap.tileHeight*2))>>0;
                if(gabarit.hitTest(circleX, circleY)){
                    shape.graphics
                        .beginFill("rgba(136,138,194,0.3)")
                        .drawCircle(circleX, circleY, (game.gameMap.tileHeight/4)>>0)
                        .endFill()
                        .beginFill("rgba(85,88,167,0.9)")
                        .rect(circleX-1, circleY-1, 2, 2)
                        .endFill();
                }else{
                    i--;
                }
            }
            break;

        case "tiny":
            //1x1
            var gabarit = new createjs.Shape();
            gabarit.regX = 0;
            gabarit.regY = 0;
            gabarit.x = x;
            gabarit.y = y;
            gabarit.graphics
                .beginFill("#fff")
                .drawEllipse((game.gameMap.tileWidth/4)-(game.gameMap.tileWidth/2)>>0, (game.gameMap.tileHeight/4)-(game.gameMap.tileHeight/2)>>0, game.gameMap.tileWidth-(game.gameMap.tileWidth/4), game.gameMap.tileHeight-(game.gameMap.tileHeight/4))
                .endFill();
            //game.mainContainer.addChild(gabarit);

            for(var i = 0; i<15; i++){
                var circleX = ((Math.random() - 0.5) * game.gameMap.tileWidth)>>0;
                var circleY = ((Math.random() - 0.5) * game.gameMap.tileHeight)>>0;
                if(gabarit.hitTest(circleX, circleY)){
                    shape.graphics
                        .beginFill("rgba(136,138,194,0.3)")
                        .drawCircle(circleX, circleY, (game.gameMap.tileHeight/4)>>0)
                        .endFill()
                        .beginFill("rgba(85,88,167,0.9)")
                        .rect(circleX-1, circleY-1, 2, 2)
                        .endFill();
                }else{
                    i--;
                }
            }
            break;
    }

    game.mainContainer.addChild(shape);
    return shape;
};
//Structures
gamerenderer.prototype.createPlayerSpawn = function(x, y, player){
    var shape = new createjs.Shape();
    shape.regX = 0;
    shape.regY = 0;
    shape.x = x;
    shape.y = y;
    shape.graphics
        .beginFill('#FFFFD4')
        //carré haut
        .moveTo(0, - (game.gameMap.tileHeight/2))
        .lineTo(- (game.gameMap.tileWidth/2), - (game.gameMap.tileHeight))
        .lineTo(0, - (game.gameMap.tileHeight/2*3))
        .lineTo((game.gameMap.tileWidth/2), - (game.gameMap.tileHeight))
        .lineTo(0, - (game.gameMap.tileHeight/2))
        //carré gauche
        .moveTo(- (game.gameMap.tileWidth/2), 0)
        .lineTo(- (game.gameMap.tileWidth), (game.gameMap.tileHeight/2))
        .lineTo(- (game.gameMap.tileWidth/2*3), 0)
        .lineTo(- (game.gameMap.tileWidth), - (game.gameMap.tileHeight/2))
        .lineTo(- (game.gameMap.tileWidth/2), 0)
        //carré bas
        .moveTo(0, (game.gameMap.tileHeight/2))
        .lineTo((game.gameMap.tileWidth/2), (game.gameMap.tileHeight))
        .lineTo(0, (game.gameMap.tileHeight/2*3))
        .lineTo(- (game.gameMap.tileWidth/2), (game.gameMap.tileHeight))
        .lineTo(0, (game.gameMap.tileHeight/2))
        //carré droit
        .moveTo((game.gameMap.tileWidth/2), 0)
        .lineTo((game.gameMap.tileWidth), - (game.gameMap.tileHeight/2))
        .lineTo((game.gameMap.tileWidth/2*3), 0)
        .lineTo((game.gameMap.tileWidth), (game.gameMap.tileHeight/2))
        .lineTo((game.gameMap.tileWidth/2), 0)
        .endFill()
        //Couloirs
        .beginFill('#878787')
        .lineTo((game.gameMap.tileWidth), (game.gameMap.tileHeight/2))
        .lineTo((game.gameMap.tileWidth/2), (game.gameMap.tileHeight))
        .lineTo(0, (game.gameMap.tileHeight/2))
        .lineTo(- (game.gameMap.tileWidth/2), (game.gameMap.tileHeight))
        .lineTo(- (game.gameMap.tileWidth), (game.gameMap.tileHeight/2))
        .lineTo(- (game.gameMap.tileWidth/2), 0)
        .lineTo(- (game.gameMap.tileWidth), - (game.gameMap.tileHeight/2))
        .lineTo(- (game.gameMap.tileWidth/2), - (game.gameMap.tileHeight))
        .lineTo(0, - (game.gameMap.tileHeight/2))
        .lineTo((game.gameMap.tileWidth/2), - (game.gameMap.tileHeight))
        .lineTo((game.gameMap.tileWidth), - (game.gameMap.tileHeight/2))
        .lineTo((game.gameMap.tileWidth/2), 0)
        .endFill();
    game.mainContainer.addChild(shape);
    return shape;
}
gamerenderer.prototype.createRoomDoor = function(orientation,size,color,shape){
    switch(size) {
        case "3":
            switch(orientation){
                case "N":
                    var coefX = 1;
                    var coefY = -1;
                    break;
                case "E":
                    var coefX = 1;
                    var coefY = 1;
                    break;
                case "S":
                    var coefX = -1;
                    var coefY = 1;
                    break;
                case "W":
                    var coefX = -1;
                    var coefY = -1;
                    break;
            }
            shape.graphics
                .beginFill("#E6C70A")
                .moveTo( (game.gameMap.tileWidth * coefX), (game.gameMap.tileHeight*0.5 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.9375 * coefX), (game.gameMap.tileHeight*0.5625 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.9375 * coefX), (game.gameMap.tileHeight*0.4375 * coefY))
                .lineTo( (game.gameMap.tileWidth * coefX), (game.gameMap.tileHeight*0.5 * coefY))
                .endFill()
                .beginFill('#878787')
                .moveTo( (game.gameMap.tileWidth * 0.9375 * coefX), (game.gameMap.tileHeight*0.5625 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.875 * coefX), (game.gameMap.tileHeight*0.625 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.875 * coefX), (game.gameMap.tileHeight*0.375 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.9375 * coefX), (game.gameMap.tileHeight*0.4375 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.9375 * coefX), (game.gameMap.tileHeight*0.5625 * coefY))
                .endFill()
                .beginFill("#E6C70A")
                .moveTo( (game.gameMap.tileWidth * 0.875 * coefX), (game.gameMap.tileHeight*0.625 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.8125 * coefX), (game.gameMap.tileHeight*0.6875 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.8125 * coefX), (game.gameMap.tileHeight*0.4375 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.875 * coefX), (game.gameMap.tileHeight*0.375 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.875 * coefX), (game.gameMap.tileHeight*0.625 * coefY))
                .endFill()
                .beginFill('#878787')
                .moveTo( (game.gameMap.tileWidth * 0.8125 * coefX), (game.gameMap.tileHeight*0.6875 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.75 * coefX), (game.gameMap.tileHeight*0.75 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.75 * coefX), (game.gameMap.tileHeight*0.5 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.8125 * coefX), (game.gameMap.tileHeight*0.4375 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.8125 * coefX), (game.gameMap.tileHeight*0.6875 * coefY))
                .endFill()
                .beginFill("#E6C70A")
                .moveTo( (game.gameMap.tileWidth * 0.75 * coefX), (game.gameMap.tileHeight*0.75 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.6875 * coefX), (game.gameMap.tileHeight*0.8125 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.6875 * coefX), (game.gameMap.tileHeight*0.5625 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.75 * coefX), (game.gameMap.tileHeight*0.5 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.75 * coefX), (game.gameMap.tileHeight*0.75 * coefY))
                .endFill()
                .beginFill('#878787')
                .moveTo( (game.gameMap.tileWidth * 0.6875 * coefX), (game.gameMap.tileHeight*0.8125 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.625 * coefX), (game.gameMap.tileHeight*0.875 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.625 * coefX), (game.gameMap.tileHeight*0.625 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.6875 * coefX), (game.gameMap.tileHeight*0.5625 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.6875 * coefX), (game.gameMap.tileHeight*0.8125 * coefY))
                .endFill()
                .beginFill("#E6C70A")
                .moveTo( (game.gameMap.tileWidth * 0.625 * coefX), (game.gameMap.tileHeight*0.875 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.5625 * coefX), (game.gameMap.tileHeight*0.9375 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.5625 * coefX), (game.gameMap.tileHeight*0.6875 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.625 * coefX), (game.gameMap.tileHeight*0.625 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.625 * coefX), (game.gameMap.tileHeight*0.875 * coefY))
                .endFill()
                .beginFill('#878787')
                .moveTo( (game.gameMap.tileWidth * 0.5625 * coefX), (game.gameMap.tileHeight*0.9375 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.5 * coefX), (game.gameMap.tileHeight * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.5 * coefX), (game.gameMap.tileHeight*0.75 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.5625 * coefX), (game.gameMap.tileHeight*0.6875 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.5625 * coefX), (game.gameMap.tileHeight*0.9375 * coefY))
                .endFill()
                .beginFill("#E6C70A")
                .moveTo( (game.gameMap.tileWidth * 0.5 * coefX), (game.gameMap.tileHeight * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.4375 * coefX), (game.gameMap.tileHeight*0.9375 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.4375 * coefX), (game.gameMap.tileHeight*0.8125 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.5 * coefX), (game.gameMap.tileHeight*0.75 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.5 * coefX), (game.gameMap.tileHeight * coefY))
                .endFill()
                .beginFill('#878787')
                .moveTo( (game.gameMap.tileWidth * 0.4375 * coefX), (game.gameMap.tileHeight*0.9375 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.375 * coefX), (game.gameMap.tileHeight*0.875 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.4375 * coefX), (game.gameMap.tileHeight*0.8125 * coefY))
                .lineTo( (game.gameMap.tileWidth * 0.4375 * coefX), (game.gameMap.tileHeight*0.9375 * coefY))
                .endFill();
            break;
    }
}
gamerenderer.prototype.createCorridor = function(x, y, player, error){
    var shape = new createjs.Shape();
    shape.regX = 0;
    shape.regY = 0;
    shape.x = x;
    shape.y = y;
    shape.graphics
        .moveTo(0, -(game.gameMap.tileHeight/2));
    if(error) {
        shape.graphics
            .beginFill('#FF4949');
    }else{
        shape.graphics
            .beginFill('#878787');
    }
    shape.graphics
        .lineTo(-(game.gameMap.tileWidth/2), 0)
        .lineTo(0, (game.gameMap.tileHeight/2))
        .lineTo((game.gameMap.tileWidth/2), 0)
        .lineTo(0, -(game.gameMap.tileHeight/2))
        .endFill();
    game.mainContainer.addChild(shape);
    return shape;
}
// ROOMS
gamerenderer.prototype.createExtractor = function(x, y, orientation, player, error){
    //3x3
    var shape = new createjs.Shape();
    shape.regX = 0;
    shape.regY = 0;
    shape.x = x;
    shape.y = y;
    if(error){
        shape.graphics
            .beginFill('#FF4949');
    }else{
        shape.graphics
            .beginFill('#888AC2');
    }
    switch(orientation){
        case "N":
            shape.graphics
                .moveTo( - (game.gameMap.tileWidth*1.125), - (game.gameMap.tileHeight*0.25))//4
                .lineTo( - (game.gameMap.tileWidth*0.125), - (game.gameMap.tileHeight*1.25))//3
                .lineTo( game.gameMap.tileWidth*0.125, - (game.gameMap.tileHeight*1.25))//2
                .lineTo( game.gameMap.tileWidth*1.25, - (game.gameMap.tileHeight*0.125))//1
                .lineTo( game.gameMap.tileWidth*1.25, game.gameMap.tileHeight*0.125)//10
                .lineTo( game.gameMap.tileWidth*0.25, game.gameMap.tileHeight*1.125)//9
                //Absorber window
                .lineTo( 0, game.gameMap.tileHeight*1.125)//8
                .lineTo( 0, game.gameMap.tileHeight*0.875)//7
                .lineTo( - (game.gameMap.tileWidth*0.875), 0)//6
                //next
                .lineTo( - (game.gameMap.tileWidth*1.125), 0)//5
                .lineTo( - (game.gameMap.tileWidth*1.125), - (game.gameMap.tileHeight*0.25))//4
                .endFill();
            break;
        case "E":
            shape.graphics
                .moveTo( game.gameMap.tileWidth*1.25, game.gameMap.tileHeight*0.125)//1
                .lineTo( game.gameMap.tileWidth*0.125, game.gameMap.tileHeight*1.25)//2
                .lineTo( - (game.gameMap.tileWidth*0.125), game.gameMap.tileHeight*1.25)//3
                .lineTo( - (game.gameMap.tileWidth*1.125), game.gameMap.tileHeight*0.25)//4
                .lineTo( - (game.gameMap.tileWidth*1.125), 0)//5
                //Absorber window
                .lineTo( - (game.gameMap.tileWidth*0.875), 0)//6
                .lineTo( 0, - (game.gameMap.tileHeight*0.875))//7
                .lineTo( 0, - (game.gameMap.tileHeight*1.125))//8
                //next
                .lineTo( game.gameMap.tileWidth*0.25, - (game.gameMap.tileHeight*1.125))
                .lineTo( game.gameMap.tileWidth*1.25, - (game.gameMap.tileHeight*0.125))
                .lineTo( game.gameMap.tileWidth*1.25, game.gameMap.tileHeight*0.125)
                .endFill();
            break;
        case "S":
            shape.graphics
                .moveTo( game.gameMap.tileWidth*1.125, game.gameMap.tileHeight*0.25)//4
                .lineTo( game.gameMap.tileWidth*0.125, game.gameMap.tileHeight*1.25)//3
                .lineTo( - (game.gameMap.tileWidth*0.125), game.gameMap.tileHeight*1.25)//2
                .lineTo( - (game.gameMap.tileWidth*1.25), game.gameMap.tileHeight*0.125)//1
                .lineTo( - (game.gameMap.tileWidth*1.25), - (game.gameMap.tileHeight*0.125))//10
                .lineTo( - (game.gameMap.tileWidth*0.25), - (game.gameMap.tileHeight*1.125))//9
                //Absorber window
                .lineTo( 0, - (game.gameMap.tileHeight*1.125))//8
                .lineTo( 0, - (game.gameMap.tileHeight*0.875))//7
                .lineTo( game.gameMap.tileWidth*0.875, 0)//6
                //next
                .lineTo( game.gameMap.tileWidth*1.125, 0)//5
                .lineTo( game.gameMap.tileWidth*1.125, game.gameMap.tileHeight*0.25)//4
                .endFill();
            break;
        case "W":
            shape.graphics
                .moveTo( - (game.gameMap.tileWidth*1.25), - (game.gameMap.tileHeight*0.125))//1
                .lineTo( - (game.gameMap.tileWidth*0.125), - (game.gameMap.tileHeight*1.25))//2
                .lineTo( game.gameMap.tileWidth*0.125, - (game.gameMap.tileHeight*1.25))//3
                .lineTo( game.gameMap.tileWidth*1.125, - (game.gameMap.tileHeight*0.25))//4
                .lineTo( game.gameMap.tileWidth*1.125, 0)//5
                //Absorber window
                .lineTo( game.gameMap.tileWidth*0.875, 0)//6
                .lineTo( 0, game.gameMap.tileHeight*0.875)//7
                .lineTo( 0, game.gameMap.tileHeight*1.125)//8
                //next
                .lineTo( - (game.gameMap.tileWidth*0.25), game.gameMap.tileHeight*1.125)
                .lineTo( - (game.gameMap.tileWidth*1.25), game.gameMap.tileHeight*0.125)
                .lineTo( - (game.gameMap.tileWidth*1.25), - (game.gameMap.tileHeight*0.125))
                .endFill();
            break;
    }
    game.gameRenderer.createRoomDoor(orientation, '3', '#888AC2', shape);
    game.mainContainer.addChild(shape);
    return shape;
}
gamerenderer.prototype.createGenerator = function(x, y, orientation, player, error){
    //3x3
    var shape = new createjs.Shape();
    shape.regX = 0;
    shape.regY = 0;
    shape.x = x;
    shape.y = y;
    if(error){
        shape.graphics
            .beginFill('#FF4949');
    }else{
        shape.graphics
            .beginFill('#E6C70A');
    }
    shape.graphics
        .moveTo( - (game.gameMap.tileWidth*1.125), - (game.gameMap.tileHeight*0.25))
        .lineTo( - (game.gameMap.tileWidth*0.25), - (game.gameMap.tileHeight*1.125))
        .quadraticCurveTo( 0, - (game.gameMap.tileHeight*1.375), game.gameMap.tileWidth*0.25, - (game.gameMap.tileHeight*1.125))
        .lineTo( game.gameMap.tileWidth*1.125, - (game.gameMap.tileHeight*0.25))
        .quadraticCurveTo( game.gameMap.tileWidth*1.375, 0, game.gameMap.tileWidth*1.125, game.gameMap.tileHeight*0.25)
        .lineTo( game.gameMap.tileWidth*0.25, game.gameMap.tileHeight*1.125)
        .quadraticCurveTo( 0, game.gameMap.tileHeight*1.375, - (game.gameMap.tileWidth*0.25), game.gameMap.tileHeight*1.125)
        .lineTo( - (game.gameMap.tileWidth*1.125), game.gameMap.tileHeight*0.25)
        .quadraticCurveTo( - (game.gameMap.tileWidth*1.375), 0, - (game.gameMap.tileWidth*1.125), - (game.gameMap.tileHeight*0.25))
        .endFill();
    game.gameRenderer.createRoomDoor(orientation, '3', '#E6C70A', shape);
    game.mainContainer.addChild(shape);
    return shape;

}
gamerenderer.prototype.createGarden = function(x, y, orientation, player, error){
    var shape = new createjs.Shape();
    shape.regX = 0;
    shape.regY = 0;
    shape.x = x;
    shape.y = y;
    if(error){
        shape.graphics
            .beginFill('#FF4949');
    }else{
        shape.graphics
            .beginFill('#52C11E');
    }
    shape.graphics
        .drawEllipse(-game.gameMap.tileWidth, -game.gameMap.tileHeight, game.gameMap.tileWidth*2, game.gameMap.tileHeight*2)
        .endFill();
    game.gameRenderer.createRoomDoor(orientation, '3', '#52C11E', shape);
    game.mainContainer.addChild(shape);
    return shape;
}
gamerenderer.prototype.createKitchen = function(x, y, orientation, player, error){
    var shape = new createjs.Shape();
    shape.regX = 0;
    shape.regY = 0;
    shape.x = x;
    shape.y = y;
    if(error){
        shape.graphics
            .beginFill('#FF4949');
    }else{
        shape.graphics
            .beginFill('#ED5751');
    }
    switch(orientation){
        case "N":
            shape.graphics
                .moveTo( game.gameMap.tileWidth*0.6875, game.gameMap.tileHeight*0.6875)
                .quadraticCurveTo( 0, game.gameMap.tileHeight*1.375, - (game.gameMap.tileWidth*0.6875), game.gameMap.tileHeight*0.6875)
                .quadraticCurveTo( - (game.gameMap.tileWidth*1.375), 0, - (game.gameMap.tileWidth*0.6875), - (game.gameMap.tileHeight*0.6875))
                .lineTo( 0, - (game.gameMap.tileHeight*1.375))
                .lineTo( game.gameMap.tileWidth*1.375, 0)
                .lineTo( game.gameMap.tileWidth*0.6875, game.gameMap.tileHeight*0.6875)
                .endFill();
            break;
        case "E":
            shape.graphics
                .moveTo( game.gameMap.tileWidth*1.375, 0)
                .lineTo( 0, game.gameMap.tileHeight*1.375)
                .lineTo( - (game.gameMap.tileWidth*0.6875), game.gameMap.tileHeight*0.6875)
                .quadraticCurveTo( - (game.gameMap.tileWidth*1.375), 0, - (game.gameMap.tileWidth*0.6875), - (game.gameMap.tileHeight*0.6875))
                .quadraticCurveTo( 0, - (game.gameMap.tileHeight*1.375), game.gameMap.tileWidth*0.6875, - (game.gameMap.tileHeight*0.6875))
                .lineTo( game.gameMap.tileWidth*1.375, 0)
                .endFill();
            break;
        case "S":
            shape.graphics
                .moveTo( game.gameMap.tileWidth*0.6875, game.gameMap.tileHeight*0.6875)//3
                .lineTo( 0, game.gameMap.tileHeight*1.375)//2
                .lineTo( - (game.gameMap.tileWidth*1.375), 0)//1
                .lineTo( - (game.gameMap.tileWidth*0.6875), - (game.gameMap.tileHeight*0.6875))//5
                .quadraticCurveTo( 0, - (game.gameMap.tileHeight*1.375), game.gameMap.tileWidth*0.6875, - (game.gameMap.tileHeight*0.6875))//4
                .quadraticCurveTo( game.gameMap.tileWidth*1.375, 0, game.gameMap.tileWidth*0.6875, game.gameMap.tileHeight*0.6875)//3
                .endFill();
            break;
        case "W":
            shape.graphics
                .moveTo( - (game.gameMap.tileWidth*1.375), 0)
                .lineTo( 0, - (game.gameMap.tileHeight*1.375))
                .lineTo( game.gameMap.tileWidth*0.6875, - (game.gameMap.tileHeight*0.6875))
                .quadraticCurveTo( game.gameMap.tileWidth*1.375, 0, game.gameMap.tileWidth*0.6875, game.gameMap.tileHeight*0.6875)
                .quadraticCurveTo( 0, game.gameMap.tileHeight*1.375, - (game.gameMap.tileWidth*0.6875), game.gameMap.tileHeight*0.6875)
                .lineTo( - (game.gameMap.tileWidth*1.375), 0)
                .endFill();
            break;
    }
    game.gameRenderer.createRoomDoor(orientation, '3', '#ED5751', shape);
    game.mainContainer.addChild(shape);
    return shape;
}
gamerenderer.prototype.createDefenceArea = function(x, y, orientation, player, error){
    var shape = new createjs.Shape();
    shape.regX = 0;
    shape.regY = 0;
    shape.x = x;
    shape.y = y;
    if(error){
        shape.graphics
            .beginFill('#FF4949');
    }else{
        shape.graphics
            .beginFill('#5B97F9');
    }
    shape.graphics
        .moveTo( - (game.gameMap.tileWidth*1.5), 0)//1
        .lineTo( - (game.gameMap.tileWidth*1.125), - (game.gameMap.tileHeight*0.25))
        .lineTo( - game.gameMap.tileWidth, - (game.gameMap.tileHeight*0.25))
        .lineTo( - game.gameMap.tileWidth, - (game.gameMap.tileHeight*0.5))
        .lineTo( - (game.gameMap.tileWidth*0.75), - (game.gameMap.tileHeight*0.5))
        .lineTo( - (game.gameMap.tileWidth*0.5), - (game.gameMap.tileHeight*0.75))
        .lineTo( - (game.gameMap.tileWidth*0.5), - game.gameMap.tileHeight)
        .lineTo( - (game.gameMap.tileWidth*0.25), - (game.gameMap.tileHeight*0.875))
        .lineTo( - (game.gameMap.tileWidth*0.125), - game.gameMap.tileHeight)
        .lineTo( 0, - (game.gameMap.tileHeight*1.5))//2
        .lineTo( game.gameMap.tileWidth*0.125, - game.gameMap.tileHeight)
        .lineTo( game.gameMap.tileWidth*0.25, - (game.gameMap.tileHeight*0.875))
        .lineTo( game.gameMap.tileWidth*0.5, - game.gameMap.tileHeight)
        .lineTo( game.gameMap.tileWidth*0.5, - (game.gameMap.tileHeight*0.75))
        .lineTo( game.gameMap.tileWidth*0.75, - (game.gameMap.tileHeight*0.5))
        .lineTo( game.gameMap.tileWidth, - (game.gameMap.tileHeight*0.5))
        .lineTo( game.gameMap.tileWidth, - (game.gameMap.tileHeight*0.25))
        .lineTo( game.gameMap.tileWidth*1.125, - (game.gameMap.tileHeight*0.25))
        .lineTo( game.gameMap.tileWidth*1.5, 0)//3
        .lineTo( game.gameMap.tileWidth*1.125, game.gameMap.tileHeight*0.25)
        .lineTo( game.gameMap.tileWidth, game.gameMap.tileHeight*0.25)
        .lineTo( game.gameMap.tileWidth, game.gameMap.tileHeight*0.5)
        .lineTo( game.gameMap.tileWidth*0.75, game.gameMap.tileHeight*0.5)
        .lineTo( game.gameMap.tileWidth*0.5, (game.gameMap.tileHeight*0.75))
        .lineTo( game.gameMap.tileWidth*0.5, game.gameMap.tileHeight)
        .lineTo( game.gameMap.tileWidth*0.25, game.gameMap.tileHeight*0.875)
        .lineTo( game.gameMap.tileWidth*0.125, game.gameMap.tileHeight)
        .lineTo( 0, game.gameMap.tileHeight*1.5)//4
        .lineTo( - (game.gameMap.tileWidth*0.125), game.gameMap.tileHeight)
        .lineTo( - (game.gameMap.tileWidth*0.25), game.gameMap.tileHeight*0.875)
        .lineTo( - (game.gameMap.tileWidth*0.5), game.gameMap.tileHeight)
        .lineTo( - (game.gameMap.tileWidth*0.5), (game.gameMap.tileHeight*0.75))
        .lineTo( - (game.gameMap.tileWidth*0.75), game.gameMap.tileHeight*0.5)
        .lineTo( - (game.gameMap.tileWidth), game.gameMap.tileHeight*0.5)
        .lineTo( - (game.gameMap.tileWidth), game.gameMap.tileHeight*0.25)
        .lineTo( - (game.gameMap.tileWidth*1.125), game.gameMap.tileHeight*0.25)
        .lineTo( - (game.gameMap.tileWidth*1.5), 0)//1
    game.gameRenderer.createRoomDoor(orientation, '3', '#5B97F9', shape);
    game.mainContainer.addChild(shape);
    return shape;
}
gamerenderer.prototype.createAADefenceArea = function(x, y, orientation, player, error){

}
gamerenderer.prototype.createLifeRoom = function(x, y, orientation, player, error){

}
gamerenderer.prototype.createInfirmary = function(x, y, orientation, player, error){

}
gamerenderer.prototype.createBunker = function(x, y, orientation, player, error){

}
gamerenderer.prototype.createResearchCenter = function(x, y, orientation, player, error){

}
gamerenderer.prototype.createAirport = function(x, y, orientation, player, error){
    var shape = new createjs.Shape();
    shape.regX = 0;
    shape.regY = 0;
    shape.x = x;
    shape.y = y;
    if(error){
        shape.graphics
            .beginFill('#FF4949');
    }else{
        shape.graphics
            .beginFill('#F30707');
    }

    shape.graphics// TODO : compléter
        .endFill();

    game.gameRenderer.createRoomDoor(orientation, '3', '#F30707', shape);
    game.mainContainer.addChild(shape);
    return shape;
}
// ROOMS STUFF
//common
gamerenderer.prototype.createSupplyArea = function(x, y, shape){

}
//extractor
gamerenderer.prototype.createExtractorMachine = function(x, y, shape){

}
//generator
gamerenderer.prototype.createNuclearPlant = function(x, y, shape){

}
//

// ENTITIES
//Noids
gamerenderer.prototype.spawnNoid = function(x, y){
    var shape = new createjs.Shape();
    shape.regX = 0;
    shape.regY = 0;
    shape.x = x;
    shape.y = y;
    shape.zIndex = y;
    shape.graphics
        .beginFill("#FFF")
        .moveTo( x - (game.gameMap.tileWidth * 0.06), y )
        .lineTo( x - (game.gameMap.tileWidth * 0.06), y - (game.gameMap.tileHeight * 0.5) )
        .lineTo( x + (game.gameMap.tileWidth * 0.06), y - (game.gameMap.tileHeight * 0.5) )
        .lineTo( x + (game.gameMap.tileWidth * 0.06), y )
        .lineTo( x - (game.gameMap.tileWidth * 0.06), y )
        .drawCircle( x, y - (game.gameMap.tileHeight * 0.53), (game.gameMap.tileWidth * 0.1) )
        .endFill()
        .beginFill("#000")
        .drawCircle( x - (game.gameMap.tileWidth * 0.032), y - (game.gameMap.tileHeight * 0.52), (game.gameMap.tileWidth * 0.013) )
        .drawCircle( x + (game.gameMap.tileWidth * 0.032), y - (game.gameMap.tileHeight * 0.52), (game.gameMap.tileWidth * 0.013) )
        .endFill();
    game.mainContainer.addChild(shape);
    return shape;
}
//Ressources
gamerenderer.prototype.spawnThorium = function(x, y, player){
    //=Thorium:   #5558A7, #7275C9, #888AC2
    var shape = new createjs.Shape();
    shape.regX = 0;
    shape.regY = 0;
    shape.x = x;
    shape.y = y;
    shape.zIndex = y+1;
    shape.graphics
        .beginFill("#7275C9")
        .moveTo( x, y - (game.gameMap.tileHeight * 0.125))
        .lineTo( x, y + (game.gameMap.tileHeight * 0.125))
        .lineTo( x - (game.gameMap.tileWidth * 0.125), y)
        .lineTo( x - (game.gameMap.tileWidth * 0.125), y - (game.gameMap.tileHeight * 0.25))
        .lineTo( x, y - (game.gameMap.tileHeight * 0.125))
        .endFill()
        .beginFill("#5558A7")
        .moveTo( x, y - (game.gameMap.tileHeight * 0.125))
        .lineTo( x + (game.gameMap.tileWidth * 0.125), y - (game.gameMap.tileHeight * 0.25))
        .lineTo( x + (game.gameMap.tileWidth * 0.125), y)
        .lineTo( x, y + (game.gameMap.tileHeight * 0.125))
        .lineTo( x, y - (game.gameMap.tileHeight * 0.125))
        .endFill()
        .beginFill("#888AC2")
        .moveTo( x, y - (game.gameMap.tileHeight * 0.125))
        .lineTo( x - (game.gameMap.tileWidth * 0.125), y - (game.gameMap.tileHeight * 0.25))
        .lineTo( x, y - (game.gameMap.tileHeight * 0.375))
        .lineTo( x + (game.gameMap.tileWidth * 0.125), y - (game.gameMap.tileHeight * 0.25))
        .lineTo( x, y - (game.gameMap.tileHeight * 0.125))
        .endFill();
    game.mainContainer.addChild(shape);
    return shape;
}
gamerenderer.prototype.spawnEnergy = function(x, y, player){
    var shape = new createjs.Shape();
    shape.regX = 0;
    shape.regY = 0;
    shape.x = x;
    shape.y = y;
    shape.zIndex = y+1;
    shape.graphics

    game.mainContainer.addChild(shape);
    return shape;
}
gamerenderer.prototype.spawnHarvest = function(x, y, player){

}
gamerenderer.prototype.spawnFood = function(x, y, player){

}
//Drone Entities
gamerenderer.prototype.spawnScoutDrone = function(x, y, player){

}
gamerenderer.prototype.spawnFighter = function(x, y, player){

}
gamerenderer.prototype.spawnBomber = function(x, y, player){

}
gamerenderer.prototype.spawnHarvester = function(x, y, player){

}